package com.buddies.lottery.widget;


import android.view.View;

import com.chad.library.R;
import com.chad.library.adapter.base.loadmore.LoadMoreView;
import com.tencent.bugly.crashreport.BuglyLog;

/**
 * Created by BlingBling on 2016/10/11.
 */

public final class TrendLoadMoreView extends LoadMoreView {

    private View mContainer;

    public void bind(View container) {
        mContainer = container;
    }

    @Override
    public int getLayoutId() {
        return R.layout.brvah_quick_view_load_more;
    }

    @Override
    protected int getLoadingViewId() {
        return R.id.load_more_loading_view;
    }

    @Override
    protected int getLoadFailViewId() {
        return R.id.load_more_load_fail_view;
    }

    @Override
    protected int getLoadEndViewId() {
        return R.id.load_more_load_end_view;
    }

    public void convert(int loadMoreStatus) {
        setLoadMoreStatus(loadMoreStatus);
        switch (loadMoreStatus) {
            case STATUS_LOADING:
                visibleLoading(true);
                visibleLoadFail(false);
                visibleLoadEnd(false);
                break;
            case STATUS_FAIL:
                visibleLoading(false);
                visibleLoadFail(true);
                visibleLoadEnd(false);
                break;
            case STATUS_END:
                visibleLoading(false);
                visibleLoadFail(false);
                visibleLoadEnd(true);
                break;
            case STATUS_DEFAULT:
                visibleLoading(false);
                visibleLoadFail(false);
                visibleLoadEnd(false);
                break;
        }
    }

    private void visibleLoading(boolean visible) {
        setGone(getLoadingViewId(), visible);
        BuglyLog.e("LotteryTrendActivity", "visibleLoading:" + visible);
    }

    private void visibleLoadFail(boolean visible) {
        setGone(getLoadFailViewId(), visible);
    }

    private void visibleLoadEnd(boolean visible) {
        setGone(getLoadEndViewId(), visible);
    }

    private void setGone(int viewId, boolean visible) {
        View view = mContainer.findViewById(viewId);
        view.setVisibility(visible ? View.VISIBLE : View.GONE);
    }


    public void loadMoreComplete() {
        convert(LoadMoreView.STATUS_DEFAULT);
    }

    public void loadMoreEnd() {
        setLoadMoreEndGone(false);
        convert(LoadMoreView.STATUS_END);
    }

    public void loadMoreFail() {
        convert(LoadMoreView.STATUS_FAIL);
    }

    public void loadMoreLoading() {
        convert(LoadMoreView.STATUS_LOADING);
    }
}
